package com.xxxx.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.xxxx.server.pojo.MenuRole;
import com.xxxx.server.mapper.MenuRoleMapper;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.service.IMenuRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhoubin
 * @since 2022-04-13
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements IMenuRoleService {
    @Autowired
    private MenuRoleMapper menuRoleMapper;
    @Override
    public RespBean deletemenurole(Integer rid, Integer[] mids) {

        menuRoleMapper.delete(new UpdateWrapper<MenuRole>().eq("rid",rid));
        if (null==mids || 0==mids.length){
            return RespBean.success("更新成功");
        }

        for (Integer mid:mids){
           if (1!=menuRoleMapper.insert(new MenuRole(rid,mid))){
               return RespBean.error("更新失败");
            }
        }

        return RespBean.success("更新成功");
    }
}
